package controller;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import multiformat.*;

import javax.swing.*;


/**
 * De controller voor de "Base" van de calculator.
 * @author Minkey
 */
public class BaseController extends JPanel implements ActionListener{
	private JComboBox baseComboBox;
	Calculator calc;
	
	/**
	 * De contructor.
	 * @param calc
	 */
	public BaseController(Calculator calc){
		this.calc = calc;
		baseComboBox = new JComboBox(new String [] {"Decimal", "Hexadecimal", "Octal", "Binary"});
		baseComboBox.setSelectedItem("Decimal");
		baseComboBox.setPreferredSize(new Dimension(150,20));
		
		baseComboBox.addActionListener(this);
		this.add(baseComboBox);
	}

	/**
	 * ActionPerformed, hier wordt geluisterd naar een action. Als er een action is uitgevoerd wordt deze hier afgehandeld.
	 * @param e
	 */
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == baseComboBox){
			
			JComboBox temp = (JComboBox) e.getSource();
			
			if(temp.getSelectedItem() == "Decimal"){
				calc.setBase(new DecimalBase());
			} else if(temp.getSelectedItem() == "Hexadecimal"){
				calc.setBase(new HexBase());
			} else if(temp.getSelectedItem() == "Octal"){
				calc.setBase(new OctBase());
			} else if(temp.getSelectedItem() == "Binary"){
				calc.setBase(new BinaryBase());
			}
		}
		
	}
	
}
